#include <bits/stdc++.h>
#include <string>
using namespace std;

struct Stack
{
    char stack[10001];
    int size;
};

struct Stack *initStack()
{
    struct Stack *s = (struct Stack *)malloc(sizeof(struct Stack));
    return s;
}

char push(struct Stack *s, char val)
{
    s->stack[s->size++] = val;
    return val;
}

char top(struct Stack *s, int t = 0)
{
    return s->stack[s->size - 1 - t];
}

char pop(struct Stack *s)
{
    char t = top(s);
    s->stack[--(s->size)] = 0;
    return t;
}

void clear(struct Stack *s)
{
    for (int i = 0; i < s->size; i++)
    {
        s->stack[i] = 0;
    }
    s->size = 0;
}

string toString(struct Stack *s)
{
    string str = "";
    if (s->size)
    {
        for (int i = 0; i < s->size; i++)
        {
            str += s->stack[i];
        }
    }
    return str;
}

bool isTF(char c)
{
    return c == 'T' || c == 'F';
}

bool isOperate(char c)
{
    return c == '&' || c == '|';
}

char translateChar(char p, char v, char o)
{
    if (o == '&')
    {
        return p == 'T' && v == 'T' ? 'T' : 'F';
    }
    else
    {
        return p == 'T' || v == 'T' ? 'T' : 'F';
    }
}

int main()
{
    struct Stack *s = initStack();
    string str;
    getline(cin, str);
    int len = str.length();
    while (len != 1)
    {
        for (int i = 0; i < len; i++)
        {
            char curr_c = str.at(i);
            if (isTF(curr_c))
            { // 是T或F
                if (s->size > 0)
                { // second_c  first_c  curr_c
                    char first_c = top(s);
                    if (first_c == '!')
                    {
                        pop(s);
                        push(s, curr_c == 'T' ? 'F' : 'T');
                    }
                    else if (s->size >= 2 && isTF(top(s, 1)) && isOperate(first_c))
                    {
                        char second_c = top(s, 1);
                        pop(s);
                        pop(s);
                        push(s, translateChar(second_c, curr_c, first_c));
                    }
                    else
                        push(s, curr_c);
                }
                else
                    push(s, curr_c);
            }
            else if (curr_c == ')')
            {
                char first_c = top(s), second_c = top(s, 1);
                if (isTF(first_c) && second_c == '(')
                {
                    pop(s);
                    pop(s);
                    push(s, first_c);
                }
                else
                    push(s, curr_c);
            }
            else
            {
                push(s, curr_c);
            }
        }
        str = toString(s);
        clear(s);
        len = str.length();
    }
    cout << str;
    return 0;
}